import Vue from 'vue'
import Vuex from 'vuex'
import { getStorage, setStorage, removeStorage } from '@/utils/storage.js'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    user: getStorage('zf-user'),
    currentCity: '上海'
  },
  mutations: {
    initUser (state, payload) {
      state.user = payload
      setStorage('zf-user', payload)
    },
    removeUser (state) {
      state.user = null // 清除vuex中的数据
      removeStorage('zf-user') // 清除本地数据
    },
    onCurrentCity (state, val) {
      state.currentCity = val
    }
  },
  actions: {
  },
  modules: {
  }
})
